﻿<template>
	<div class="card-fill layout-padding" v-loading="loading" element-loading-text="Loading...">
		<el-tabs v-model="activeTab">
			<el-tab-pane label="培训批次信息" name="main">
				<el-card shadow="hover" class="layout-padding-auto create-form">
					<el-form ref="formRef" :model="stateData.vmModel" label-width="120px">
						<div class="form-section">
							<div class="section-title">
								<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
								<span>培训批次信息</span>
							</div>

							<el-row :gutter="20">
								<el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_TrainName_FormItem" prop="Entity.TrainName">
										<template #label>
											<WtmLabelTooltip label="培训名称" tooltip="培训项目名称" />
										</template>
										<el-input v-model="stateData.vmModel.Entity.TrainName" disabled clearable class="width100"></el-input>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_TrainStartDate_FormItem" prop="Entity.TrainStartDate">
										<template #label>
											<WtmLabelTooltip label="培训开始日期" tooltip="培训开始日期" />
										</template>
										<el-date-picker v-model="stateData.vmModel.Entity.TrainStartDate" disabled clearable class="width100"></el-date-picker>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_TrainEndDate_FormItem" prop="Entity.TrainEndDate">
										<template #label>
											<WtmLabelTooltip label="培训结束日期" tooltip="培训结束日期" />
										</template>
										<el-date-picker v-model="stateData.vmModel.Entity.TrainEndDate" disabled clearable class="width100"></el-date-picker>
									</el-form-item>
								</el-col>
								<el-col :xs="24" :lg="12" class="mb20">
									<el-form-item ref="Entity_ExamDate_FormItem" prop="Entity.ExamDate">
										<template #label>
											<WtmLabelTooltip label="培训考试日期" tooltip="培训考试日期" />
										</template>
										<el-date-picker v-model="stateData.vmModel.Entity.ExamDate" disabled clearable class="width100"></el-date-picker>
									</el-form-item>
								</el-col>
							</el-row>
						</div>

						<el-row :gutter="20"> </el-row>

						<div style="text-align: right">
							<WtmButton @click="onClose" type="default" :button-text="$t('message._system.common.vm.cancel')" style="margin-top: 15px" />
						</div>
					</el-form>
				</el-card>
			</el-tab-pane>
			<el-tab-pane label="培训考试表" name="persontrainexams" v-if="stateData.vmModel.Entity.ID"
				><SysPersonTrainExam :search-bar="false" :toolbar="false" :is-disabled="true"
			/></el-tab-pane>
		</el-tabs>
	</div>
</template>

<script setup lang="ts" name="message._system.common.vm.edit;false">
import { reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { SysPersonTrainBatcheApi as api } from '/@/views/person/syspersontrainbatche/api';
import other from '/@/utils/other';
import { ISysPersonTrainBatcheVm } from '/@/views/person/syspersontrainbatche/api/interface';
import { IViewModel } from '/@/types/common';

import SysPersonTrainExam from '/@/views/person/syspersontrainexam/index.vue';

const ci = getCurrentInstance() as any;
const loading = ref(false);
// 定义变量内容
const formRef = ref();
const stateData = reactive<IViewModel<ISysPersonTrainBatcheVm>>({
	vmModel: {
		Entity: {
			ID: null,
			TrainName: null,
			TrainStartDate: null,
			TrainEndDate: null,
			ExamDate: null,
		},
	},
});

// 取消
const onClose = () => {
	closeDialog();
};

const activeTab = ref('main');

// 页面加载时
onMounted(() => {
	loading.value = true;
	if (ci.attrs['wtmdata']) {
		stateData.vmModel.Entity.ID = ci.attrs['wtmdata'].ID;
		
	}
	const promises: Promise<any>[] = [
		api()
			.get(stateData.vmModel.Entity.ID ?? '')
			.then((data: any) => other.setValue(stateData.vmModel, data)),
	];
	Promise.allSettled(promises).finally(() => {
		loading.value = false;
		nextTick(() => {
			setupHeaderButtons();
		});
	});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh', 'closeDialog','updateHeaderButtons']);
// 关闭弹窗
const closeDialog = () => {
	emit('closeDialog');
};
// 设置对话框头部按钮
const setupHeaderButtons = () => {
	const headerButtons = [
		{
			text: ci.proxy.$t('message._system.common.vm.cancel'),
			type: 'default',
			onClick: onClose,
			visible: true,
		},
	];
	emit('updateHeaderButtons', headerButtons);
};
</script>
